#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define NORMAL_TEXT "log.normal"
#define ERROR_TEXT "log.error"

int main()
{
  fprintf(stdout, "hello fprintf\n");

  const char* buff = "hello write\n";
  write(1, buff, strlen(buff));

  fork();




  //int fd = open(NORMAL_TEXT, O_WRONLY | O_APPEND);
  //
  //dup2(fd, 1);

  //printf("you can see me !\n");
  //close(fd);

  // 手动重定向 
  //close(1);
  //close(2);
  //
  //int fd1 = open(NORMAL_TEXT, O_WRONLY | O_CREAT, 0666);
  //int fd2 = open(ERROR_TEXT, O_WRONLY | O_CREAT, 0666);
  //

  //fprintf(stdout, "stdout, printf\n");
  //fprintf(stdout, "stdout, printf\n");
  //fprintf(stdout, "stdout, printf\n");
  //fprintf(stderr, "stderr, printf\n");
  //fprintf(stderr, "stderr, printf\n");
  //fprintf(stderr, "stderr, printf\n");


  //close(0);
  //int fd = open(TEXT, O_RDONLY);

  //char buff[1024];
  //scanf("%s", buff);
  //printf("%s\n", buff);

  // 输出重定向
  //close(1);
  //int fd = open(TEXT, O_WRONLY | O_CREAT | O_TRUNC, 0666);

  //printf("You can see me!\n");
  //printf("You can see me!\n");
  //printf("You can see me!\n");
  //printf("You can see me!\n");

  //close(fd);
  //fclose(stdin);
  //fclose(stderr);
  //int fd1 = open(TEXT, O_WRONLY | O_CREAT, 0666);
  //int fd2 = open(TEXT, O_WRONLY | O_CREAT, 0666);
  //int fd3 = open(TEXT, O_WRONLY | O_CREAT, 0666);
  //int fd4 = open(TEXT, O_WRONLY | O_CREAT, 0666);

  //printf("fd1: %d\n", fd1);
  //printf("fd2: %d\n", fd2);
  //printf("fd3: %d\n", fd3);
  //printf("fd4: %d\n", fd4);

  //fprintf(stdout, "hello stdout\n");
  //fprintf(stdout, "hello stdout\n");
  //fprintf(stderr, "hello stderr\n");
  //fprintf(stderr, "hello stderr\n");

  //printf("stdin -> fd: %d\n", stdin->_fileno);
  //printf("stdout-> fd: %d\n", stdout->_fileno);
  //printf("stderr-> fd: %d\n", stderr->_fileno);
  return 0;
}
